package com.iwomy.secureplat.platform.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iwomy.secureplat.common.core.util.R;
import com.iwomy.secureplat.common.log.annotation.SysLog;
import com.iwomy.secureplat.platform.dto.BasicAlarmContactsTimeDTO;
import com.iwomy.secureplat.platform.entity.BasicAlarmContactsTimeEntity;
import com.iwomy.secureplat.platform.service.BasicAlarmContactsTimeService;
import com.iwomy.secureplat.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 接警人接警时段表
 *
 * @author pig
 * @date 2024-01-03 15:41:31
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/basicAlarmContactsTime" )
@Tag(description = "basicAlarmContactsTime" , name = "接警人接警时段表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class BasicAlarmContactsTimeController {

    private final  BasicAlarmContactsTimeService basicAlarmContactsTimeService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param basicAlarmContactsTime 接警人接警时段表
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    public R getBasicAlarmContactsTimePage(@ParameterObject Page page, @ParameterObject BasicAlarmContactsTimeEntity basicAlarmContactsTime) {
        LambdaQueryWrapper<BasicAlarmContactsTimeEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(BasicAlarmContactsTimeEntity::getAlarmContactsId,basicAlarmContactsTime.getAlarmContactsId());
        return R.ok(basicAlarmContactsTimeService.page(page, wrapper));
    }

	/**
	 * 分页查询
	 * @param basicAlarmContactsTime 接警人接警时段表
	 * @return
	 */
	@Operation(summary = "分页查询" , description = "分页查询" )
	@GetMapping("/list" )
	public R getBasicAlarmContactsTimeList(@ParameterObject BasicAlarmContactsTimeEntity basicAlarmContactsTime) {
		LambdaQueryWrapper<BasicAlarmContactsTimeEntity> wrapper = Wrappers.lambdaQuery();
		wrapper.eq(BasicAlarmContactsTimeEntity::getAlarmContactsId,basicAlarmContactsTime.getAlarmContactsId());
		return R.ok(basicAlarmContactsTimeService.list(wrapper));
	}

    /**
     * 通过id查询接警人接警时段表
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(basicAlarmContactsTimeService.getById(id));
    }

    /**
     * 新增接警人接警时段表
     * @param basicAlarmContactsTimeDTO 接警人接警时段表
     * @return R
     */
    @Operation(summary = "新增接警人接警时段表" , description = "新增接警人接警时段表" )
    @SysLog("新增接警人接警时段表" )
    @PostMapping
    public R save(@RequestBody BasicAlarmContactsTimeDTO basicAlarmContactsTimeDTO) {
        return basicAlarmContactsTimeService.newlyAdded(basicAlarmContactsTimeDTO);
    }

    /**
     * 修改接警人接警时段表
     * @param basicAlarmContactsTime 接警人接警时段表
     * @return R
     */
    @Operation(summary = "修改接警人接警时段表" , description = "修改接警人接警时段表" )
    @SysLog("修改接警人接警时段表" )
    @PutMapping
    public R updateById(@RequestBody BasicAlarmContactsTimeEntity basicAlarmContactsTime) {
        return R.ok(basicAlarmContactsTimeService.updateById(basicAlarmContactsTime));
    }

    /**
     * 通过id删除接警人接警时段表
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除接警人接警时段表" , description = "通过id删除接警人接警时段表" )
    @SysLog("通过id删除接警人接警时段表" )
    @DeleteMapping
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(basicAlarmContactsTimeService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param basicAlarmContactsTime 查询条件
   	 * @param ids 导出指定ID
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    public List<BasicAlarmContactsTimeEntity> export(BasicAlarmContactsTimeEntity basicAlarmContactsTime,Long[] ids) {
        return basicAlarmContactsTimeService.list(Wrappers.lambdaQuery(basicAlarmContactsTime).in(ArrayUtil.isNotEmpty(ids), BasicAlarmContactsTimeEntity::getId, ids));
    }
}